home *** CD-ROM | disk | FTP | other *** search
/ Java Certification Exam Guide / McGrawwHill-JavaCertificationExamGuide.iso / pc / Web Links and Code / code / chap21 / DBServer.java < prev    next >
Encoding:
Java Source  |  1997-04-20  |  1.5 KB  |  64 lines

  1. package server;
  2.  
  3. import java.io.*;
  4. import java.rmi.*;
  5. import java.rmi.server.*;
  6.  
  7. public class DBServer extends UnicastRemoteObject
  8.    implements DBInterface
  9. {
  10.    private static final String FILE_NAME = "test.db";
  11.    private DB db;
  12.  
  13.    public DBServer() throws RemoteException, IOException {     
  14.       db = new DB(FILE_NAME);
  15.    }
  16.  
  17.    public synchronized void close() throws RemoteException {
  18.       db.close();
  19.    }
  20.  
  21.    public synchronized void rewind() 
  22.       throws IOException, RemoteException 
  23.    {
  24.       db.rewind();
  25.    }
  26.  
  27.    public synchronized boolean moreRecords() 
  28.       throws IOException, RemoteException 
  29.    {
  30.       return db.moreRecords();
  31.    }
  32.  
  33.    public synchronized EmployeeRecord readRecord()
  34.       throws IOException, EOFException, RemoteException
  35.    {
  36.       return db.readRecord();
  37.    }
  38.  
  39.    public synchronized void writeRecord(EmployeeRecord record)
  40.       throws IOException, RemoteException
  41.    {
  42.       db.writeRecord(record);
  43.    }
  44.  
  45.    public static void main(String[] args) {
  46.   
  47.       // Create and install a security manager
  48.       System.setSecurityManager(new RMISecurityManager());
  49.  
  50.       try {
  51.          DBServer dbServer = new DBServer();
  52.  
  53.          Naming.rebind("DBServer", dbServer);
  54.             // located on the same machine as the client
  55.  
  56.          System.out.println("DBServer bound in registry");
  57.       } catch (Exception e) {
  58.          System.out.println("DBServer err: " + e.getMessage());
  59.          e.printStackTrace();
  60.       }
  61.    }
  62.  
  63. }
  64.